<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>添加影视</title>
</head>
<body>
<h1>添加影视</h1>
<form id="myForm">
    <table>
        <tr>
            <td>影视名称</td>
            <td><input type="text" placeholder="请输入影视名称" id="title" name="title"></td>
        </tr>
        <tr>
            <td>主演</td>
            <td><input type="text" placeholder="请输入主演" id="actors" name="actors"></td>
        </tr>
        <tr>
            <td>选择分类</td>
            <td>
                <select id="category" name="category">
                    <option value="电视剧" selected>电视剧</option>
                    <option value="电影">电影</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>选择语言</td>
            <td>
                <select name="languageId" id="languageId"></select>
            </td>
        </tr>
        <tr>
            <td>集数</td>
            <td>
                <input type="text" placeholder="请输输入集数" id="nums" name="nums">
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="button" value="添加" onclick="save()">
                <input type="reset" value="返回">
            </td>
        </tr>
    </table>
</form>

</body>
<script src="js/jquery.js"></script>
<script>
    $(function () {
        //查询所有影视语言分类
        queryLanguageCategory();
    })
    //查询所有影视语言分类
    function queryLanguageCategory() {
        $.getJSON("/findAllLanguageCategory",function (data) {
            $.each(data,function (index,ele) {
                let op=`<option value="${ele.id}">${ele.name}</option>`;
                $("#languageId").append(op);
            })
        })
    }
    //保存影视作品
    function save() {
        $.post("/save",$("#myForm").serialize(),function (data) {
            if(data.result==true){
                alert("新增成功");
                window.location.href="/index";
            }else{
                alert("新增失败");
            }
        },"json")
    }
</script>
</html>
